import axios from 'axios'
import store from "@/store";
import {getToken} from "@/utils/auth";
import service from "@/utils/request";

// create an axios instance
const service2 = axios.create({
  baseURL: '/api', // url = base url + request url
  // withCredentials: true, // send cookies when cross-domain requests
  timeout: 5000 * 60 // request timeout
});

service2.interceptors.request.use(
    config => {
      // do something before request is sent
       console.log(config)
        if (config.url.indexOf("login") === -1) {
            config.headers['Authorization'] = `Bearer ${getToken()}`;
        }
        return config
    },
    error => {
      // do something with request error
      console.log(error) // for debug
      return Promise.reject(error)
    }
)

export default service2
